<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>用户业务服务定义类管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			
			var msgType = "${userBusiness.msgType}";
			msgType = (msgType==null || msgType=='') ?'text':msgType;
			changeType(msgType);
			cleanValue();
			
			$("#name").focus();
			//settingValues();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
		
		
		
		function settingValues(){
			
			var checkText=$("#select_id").find("option:selected").text();   //获取Select选择的Text   
			var checkValue=$("#select_id").val();   //获取Select选择的Value 
			
			$('#bname').val(checkText);
			$('#config_id').val(checkValue);
			var userId = $('#userId').val();
			$.post('${ctx}/wechat/userBusiness/getUserBusiness',{'userId':userId,'configId':checkValue},function(data){
				
				if(data != null && data != undefined){
					if(data.id != null && data.id != 'null'){
						$('#userBusiness_id').val(data.id);
					}else{
						$('#userBusiness_id').val('');
					}
					if(data.content != null && data.content != 'null'){
						$('#content_id').html(data.content);
					}else{
						$('#content_id').html('');
					}
				}else{
					$('#userBusiness_id').val('');
					$('#content_id').html('');
				}
			});
		}
		
		
		
		
		function changeType(v){
			if('text' === v){
				$('#musicContent').hide();
				$('#newsReplyData').hide();
				$('#pureTextContent').show();
			}else if('music' === v){
				$('#pureTextContent').hide();
				$('#musicContent').show();
				$('#newsReplyData').hide();
			}else if('news' === v){
				$('#musicContent').show();
				$('#newsReplyData').show();
				$('#pureTextContent').hide();
			}else{
				$('#newsReplyData').hide();
				$('#musicContent').hide();
				$('#pureTextContent').show();
			}
		}
		
		
		function cleanValue(){
			$('#pic_desc').val('');
			$('#pic_title').val('');
			$('#pic_url').val('');
		}
		
		
		
		function updateReplyType(id){
			var msgType = $('input[name="msgType"]:checked').val();
			$.post("${ctx}/wechat/userBusiness/updateReplyType?id="+id+"&msgType="+msgType,function(data){
				if(data['success'] == '1'){
					$('#showMsg').addClass("alert");
					$('#showMsg').html("更新成功!");
					alert(msgType);
				} else{
				}
			});
		}
		
		
		function deleteNewsreply(id){
			
			if(confirm("您确认要删除本条记录吗?")){
				$.post("${ctx}/wechat/businessNewsReply/ajaxDelete?id="+id,function(data){
					if(data['success']){
						$('#tr'+id).remove();
					}else{
						alert("删除失败!");
					}
				});
			} 
			
		}
		
		
		
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/wechat/userBusiness/">用户业务服务定义类列表</a></li>
		<li class="active"><a href="${ctx}/wechat/userBusiness/form?id=${userBusiness.id}">用户业务服务定义类<shiro:hasPermission name="wechat:userBusiness:edit">${not empty userBusiness.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="wechat:userBusiness:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/>
	
	
	
	
	<form:form id="inputForm" name="inputForm" modelAttribute="userBusiness" action="${ctx}/wechat/userBusiness/save" method="post" class="form-horizontal" enctype="multipart/form-data">
		<form:hidden path="user.id" id="userId"/>
		<form:hidden path="businessConfig.id"  value="${userBusiness.businessConfig.id }"/>
		<tags:message content="${message}"/>
		
		<div class="control-group">
			<label class="control-label">名称:</label>
			<div class="controls">
				 <input name="name" value="${userBusiness.businessConfig.name }" readonly="readonly"/>
			</div>
		</div>
		
		<div class="control-group">
			<div class="control-group">
				<label class="control-label">回复类型:</label>
				<div class="controls">
  					<form:radiobutton   path="msgType" id="reaio" value="text"  checked="checked" onclick="changeType(this.value)"/> 文字
  					<form:radiobutton   path="msgType" id="reaio" value="news"  onclick="changeType(this.value)"/> 图文
  					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void();" onclick="updateReplyType('${userBusiness.id}');"  class="btn btn-success">更新回复类型</a>	<span id="showMsg"></span>
				</div>
				
			</div>
		</div>
			
			
			
			
		<div id="pureTextContent" class="control-group">
			<label class="control-label">回复内容:</label>
			<div class="controls">
				<textarea name="content" rows="4" cols="4"  class="required" >${userBusiness.content }</textarea>
				<span class="alert alert-success">${userBusiness.businessConfig.remarks }</span>
			</div>
		</div>
		
		
		
		<div id="musicContent" class="control-group">
				<label class="control-label">图片标题:</label>
				<div   class="controls" >
					<input type="text" name="title" htmlEscape="false" id="pic_title"  class="required"/>
				</div>
				
				<label class="control-label">链接地址:</label>
				<div   class="controls" style="margin-top:5px;margin-buttom:5px;">
					<input type="text" name="url" htmlEscape="false"  id="pic_url"/>  &nbsp; <span class="alert">必须以 http://开头,替换参数:%uid%为商家ID,%wid%为微信ID</span>
				</div>
				<label class="control-label">图片描述:</label>
				<div   class="controls" style="margin-top:5px;margin-buttom:5px;">
					<textarea id="pic_desc" name="description" htmlEscape="false"  cols="6" rows="5" class="required"></textarea>
				</div>
				<label class="control-label">上传文件:</label>
				<div class="controls" id="uploadfile">
					<input type="file"  name="picfile"/> <span class="alert">大图片建议尺寸：720像素 * 400像素;  &nbsp; 小图片建议尺寸：400像素 * 400像素</span>    
				</div>
				
			</div>
		
		<div class="form-actions">
				<shiro:hasPermission name="wechat:userBusiness:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>
				<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
			
		
		
		</form:form>
		
		
		
	<div id="newsReplyData"  style="display:none">
	<table id="contentTable" class="table table-striped table-bordered" >
		<thead>
			<tr> 
			<th width="20%">图片标题</th>
			<th width="30%">描述</th>
			<th width="30%">原文链接</th>
			<shiro:hasPermission name="wechat:newsReply:edit"><th>操作</th></shiro:hasPermission>
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${newsReplyList}" var="newsReply">
			<tr id="tr${newsReply.id }">
				<td width="20%">${newsReply.title}</td>
				<td width="30%">${newsReply.description}</td>
				<td width="30%"><a href="${newsReply.url}" target="_blank">${newsReply.url}</a> </td>
				<shiro:hasPermission name="wechat:newsReply:edit">
				<td >
					<a href="${ctx}/wechat/businessNewsReply/form?id=${newsReply.id}&type=${newsReply.type}" >修改</a>
					<a href="javascript:void(0);" onclick="deleteNewsreply('${newsReply.id}')">删除</a>
				</td></shiro:hasPermission>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	</div>
	
</body>
</html>
